/*
  @description: 测试类
 * @author: L.Wen
 * @create: 2018-09-29 14:21
 */

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.Test;


public class TestBD {
    private static WebDriver driver;
    private WebElement webElement = null;

    static {
        //告诉系统chromedriver.exe的位置
        System.setProperty("webdriver.chrome.driver", "C:\\Programs\\chromedriver_win32\\chromedriver.exe");
        driver = new ChromeDriver();
    }

    @Test()
    public void openBD() {
        System.out.println("Test openBD! \n");
        driver.get("http://www.baidu.com");
        driver.manage().window().maximize();
    }

    @Test(priority = 10)
    public void searchCSDN() throws InterruptedException {
        System.out.println("Test searchCSDN! \n");
        webElement = driver.findElement(By.xpath("//input[@id = \"kw\"]"));
        webElement.sendKeys("csdn");
        webElement = driver.findElement(By.xpath("//*[@id=\"su\"]"));
        webElement.click();
        Thread.sleep(3001);
    }

    @Test(priority = 20)
    public void checkSearchResult() {
        System.out.println("Test checkSearchResult! \n");
        String pageSourcerce = driver.getPageSource();
        System.out.println("pageSourcerce: \n" + pageSourcerce);
        Assert.assertTrue(pageSourcerce.contains("CSDN-专业IT技术社区"));
        webElement = driver.findElement(By.xpath("//*[@class=\"favurl\"]"));
        webElement.click();
    }
}

